---
keywords: ""
title: "SIMD3"
layout: "default"
root: "/v5.1"
description: "Swift documentation for 'SIMD3'"
---

<div class="intro-declaration"><code class="language-swift">struct SIMD3</code></div><p>A vector of three scalar values.</p>
<table class="standard"><tr><th id="inheritance">Inheritance</th><td><code class="inherits">SIMD, CustomDebugStringConvertible</code></td></tr><tr><th id="aliases">Associated Types</th><td><span id="aliasesmark"></span><div class="declaration"><code class="language-swift">public typealias MaskStorage = SIMD3&lt;Scalar.SIMDMaskScalar></code><div class="comment"></div></div></td></tr></table><div class="discussion comment"></div><h3>Initializers</h3><div id="init-e67906ab4373125a18eb2b5a75f59bd2" class="declaration"><a class="toggle-link" href="#comment-init-e67906ab4373125a18eb2b5a75f59bd2">init init()</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init-e67906ab4373125a18eb2b5a75f59bd2"><p>Creates a vector with zero in all lanes.</p>
<h4>Declaration</h4><code class="language-swift">public init()</code></div></div><div id="init-00a2b987552997ee43208aca83ac6ae6" class="declaration"><a class="toggle-link" href="#comment-init-00a2b987552997ee43208aca83ac6ae6">init init(_:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init-00a2b987552997ee43208aca83ac6ae6"><p>Creates a vector from the given sequence.</p>
<blockquote>
<p>Precondition:
<code>scalars</code> must have the same number of elements as the vector type.</p>
</blockquote>
<ul>
<li>Parameter scalars: The elements to use in the vector.</li>
</ul>
<h4>Declaration</h4><code class="language-swift">@inlinable public init&lt;S>(_ scalars: S) where S: Sequence, Self.Scalar == S.Element</code></div></div><div id="init-2e71c0d0c2f86f002587ef244efe09da" class="declaration"><a class="toggle-link" href="#comment-init-2e71c0d0c2f86f002587ef244efe09da">init init(_:_:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init-2e71c0d0c2f86f002587ef244efe09da"><p>A three-element vector created by appending a scalar to a two-element vector.</p>
<h4>Declaration</h4><code class="language-swift">public init(_ xy: SIMD2&lt;Scalar>, _ z: Scalar)</code></div></div><div id="init-05e023e840ef7e7bfbba997f183d187d" class="declaration"><a class="toggle-link" href="#comment-init-05e023e840ef7e7bfbba997f183d187d">init init(_:_:_:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init-05e023e840ef7e7bfbba997f183d187d"><p>Creates a new vector from the given elements.</p>
<h4>Declaration</h4><code class="language-swift">public init(_ v0: Scalar, _ v1: Scalar, _ v2: Scalar)</code></div></div><div id="init_arrayLiteral-122bf8141cc945de0f292024b4f08315" class="declaration"><a class="toggle-link" href="#comment-init_arrayLiteral-122bf8141cc945de0f292024b4f08315">init init(arrayLiteral:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init_arrayLiteral-122bf8141cc945de0f292024b4f08315"><p>Creates a vector from the specified elements.</p>
<ul>
<li>Parameter scalars: The elements to use in the vector. <code>scalars</code> must
have the same number of elements as the vector type.</li>
</ul>
<h4>Declaration</h4><code class="language-swift">@inlinable public init(arrayLiteral scalars: Self.Scalar)</code></div></div><div id="init_from-ac2c581668ee6074e8eee083d88ea873" class="declaration"><a class="toggle-link" href="#comment-init_from-ac2c581668ee6074e8eee083d88ea873">init init(from:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init_from-ac2c581668ee6074e8eee083d88ea873"><p>Creates a new vector by decoding scalars from the given decoder.</p>
<p>This initializer throws an error if reading from the decoder fails, or
if the data read is corrupted or otherwise invalid.</p>
<ul>
<li>Parameter decoder: The decoder to read data from.</li>
</ul>
<h4>Declaration</h4><code class="language-swift">public init(from decoder: Decoder) throws</code></div></div><div id="init_repeating-5e4e720f767ac20d10afec2514e82848" class="declaration"><a class="toggle-link" href="#comment-init_repeating-5e4e720f767ac20d10afec2514e82848">init init(repeating:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init_repeating-5e4e720f767ac20d10afec2514e82848"><p>A vector with the specified value in all lanes.</p>
<h4>Declaration</h4><code class="language-swift">public init(repeating value: Self.Scalar)</code></div></div><div id="init_x_y_z-aa86f151236ed1062db0309576afcf8a" class="declaration"><a class="toggle-link" href="#comment-init_x_y_z-aa86f151236ed1062db0309576afcf8a">init init(x:y:z:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-init_x_y_z-aa86f151236ed1062db0309576afcf8a"><p>Creates a new vector from the given elements.</p>
<h4>Declaration</h4><code class="language-swift">public init(x: Scalar, y: Scalar, z: Scalar)</code></div></div><h3>Instance Variables</h3><div id="debugDescription-15dc1a07010ea28e38b1f4d74663fe11" class="declaration"><a class="toggle-link" href="#comment-debugDescription-15dc1a07010ea28e38b1f4d74663fe11">var debugDescription</a> <span class="required">Required</span><div class="comment collapse in" id="comment-debugDescription-15dc1a07010ea28e38b1f4d74663fe11"><p>A textual representation of this instance, suitable for debugging.</p>
<p>Calling this property directly is discouraged. Instead, convert an
instance of any type to a string by using the <code>String(reflecting:)</code>
initializer. This initializer works with any type, and uses the custom
<code>debugDescription</code> property for types that conform to
<code>CustomDebugStringConvertible</code>:</p>
<pre><code class="language-swift">struct Point: CustomDebugStringConvertible {
    let x: Int, y: Int

    var debugDescription: String {
        return &quot;(\(x), \(y))&quot;
    }
}

let p = Point(x: 21, y: 30)
let s = String(reflecting: p)
print(s)
// Prints &quot;(21, 30)&quot;
</code></pre>
<p>The conversion of <code>p</code> to a string in the assignment to <code>s</code> uses the
<code>Point</code> type's <code>debugDescription</code> property.</p>
<h4>Declaration</h4><code class="language-swift">var debugDescription: String</code></div></div><div id="description-67daf92c833c41c95db874e18fcb2786" class="declaration"><a class="toggle-link" href="#comment-description-67daf92c833c41c95db874e18fcb2786">var description</a> <span class="required">Required</span><div class="comment collapse in" id="comment-description-67daf92c833c41c95db874e18fcb2786"><p>A textual description of the vector.</p>
<h4>Declaration</h4><code class="language-swift">var description: String</code></div></div><div id="indices-a51a528f35c02157e603a20c8796a684" class="declaration"><a class="toggle-link" href="#comment-indices-a51a528f35c02157e603a20c8796a684">var indices</a> <span class="required">Required</span><div class="comment collapse in" id="comment-indices-a51a528f35c02157e603a20c8796a684"><p>The valid indices for subscripting the vector.</p>
<h4>Declaration</h4><code class="language-swift">var indices: Range&lt;Int></code></div></div><div id="scalarCount-2c88ac4714aa7276da0950dfc969879e" class="declaration"><a class="toggle-link" href="#comment-scalarCount-2c88ac4714aa7276da0950dfc969879e">var scalarCount</a> <span class="required">Required</span><div class="comment collapse in" id="comment-scalarCount-2c88ac4714aa7276da0950dfc969879e"><p>The number of scalars in the vector.</p>
<h4>Declaration</h4><code class="language-swift">var scalarCount: Int</code></div></div><div id="x-9dd4e461268c8034f5c8564e155c67a6" class="declaration"><a class="toggle-link" href="#comment-x-9dd4e461268c8034f5c8564e155c67a6">var x</a> <span class="required">Required</span><div class="comment collapse in" id="comment-x-9dd4e461268c8034f5c8564e155c67a6"><p>The first element of the vector.</p>
<h4>Declaration</h4><code class="language-swift">var x: Scalar</code></div></div><div id="y-415290769594460e2e485922904f345d" class="declaration"><a class="toggle-link" href="#comment-y-415290769594460e2e485922904f345d">var y</a> <span class="required">Required</span><div class="comment collapse in" id="comment-y-415290769594460e2e485922904f345d"><p>The second element of the vector.</p>
<h4>Declaration</h4><code class="language-swift">var y: Scalar</code></div></div><div id="z-fbade9e36a3f36d3d676c1b808451dd7" class="declaration"><a class="toggle-link" href="#comment-z-fbade9e36a3f36d3d676c1b808451dd7">var z</a> <span class="required">Required</span><div class="comment collapse in" id="comment-z-fbade9e36a3f36d3d676c1b808451dd7"><p>The third element of the vector.</p>
<h4>Declaration</h4><code class="language-swift">var z: Scalar</code></div></div><h3>Subscripts</h3><div id="subscript_index-293ad0a56dee4ecca71b95ccc73897e9" class="declaration"><a class="toggle-link" href="#comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9">subscript subscript(index:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9"><p>Accesses the scalar at the specified position.</p>
<h4>Declaration</h4><code class="language-swift">public subscript(index: Int) -> Scalar</code></div></div><div id="subscript_index-293ad0a56dee4ecca71b95ccc73897e9" class="declaration"><a class="toggle-link" href="#comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9">subscript subscript(index:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9"><p>Extracts the scalars at specified indices to form a SIMD2.</p>
<p>The elements of the index vector are wrapped modulo the count of elements
in this vector. Because of this, the index is always in-range and no trap
can occur.</p>
<h4>Declaration</h4><code class="language-swift">public subscript&lt;Index>(index: SIMD2&lt;Index>) where Index: FixedWidthInteger, Index: SIMDScalar, Self.Scalar: SIMDScalar -> SIMD2&lt;Self.Scalar></code></div></div><div id="subscript_index-293ad0a56dee4ecca71b95ccc73897e9" class="declaration"><a class="toggle-link" href="#comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9">subscript subscript(index:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9"><p>Extracts the scalars at specified indices to form a SIMD3.</p>
<p>The elements of the index vector are wrapped modulo the count of elements
in this vector. Because of this, the index is always in-range and no trap
can occur.</p>
<h4>Declaration</h4><code class="language-swift">public subscript&lt;Index>(index: SIMD3&lt;Index>) where Index: FixedWidthInteger, Index: SIMDScalar, Self.Scalar: SIMDScalar -> SIMD3&lt;Self.Scalar></code></div></div><div id="subscript_index-293ad0a56dee4ecca71b95ccc73897e9" class="declaration"><a class="toggle-link" href="#comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9">subscript subscript(index:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9"><p>Extracts the scalars at specified indices to form a SIMD4.</p>
<p>The elements of the index vector are wrapped modulo the count of elements
in this vector. Because of this, the index is always in-range and no trap
can occur.</p>
<h4>Declaration</h4><code class="language-swift">public subscript&lt;Index>(index: SIMD4&lt;Index>) where Index: FixedWidthInteger, Index: SIMDScalar, Self.Scalar: SIMDScalar -> SIMD4&lt;Self.Scalar></code></div></div><div id="subscript_index-293ad0a56dee4ecca71b95ccc73897e9" class="declaration"><a class="toggle-link" href="#comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9">subscript subscript(index:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9"><p>Extracts the scalars at specified indices to form a SIMD8.</p>
<p>The elements of the index vector are wrapped modulo the count of elements
in this vector. Because of this, the index is always in-range and no trap
can occur.</p>
<h4>Declaration</h4><code class="language-swift">public subscript&lt;Index>(index: SIMD8&lt;Index>) where Index: FixedWidthInteger, Index: SIMDScalar, Self.Scalar: SIMDScalar -> SIMD8&lt;Self.Scalar></code></div></div><div id="subscript_index-293ad0a56dee4ecca71b95ccc73897e9" class="declaration"><a class="toggle-link" href="#comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9">subscript subscript(index:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9"><p>Extracts the scalars at specified indices to form a SIMD16.</p>
<p>The elements of the index vector are wrapped modulo the count of elements
in this vector. Because of this, the index is always in-range and no trap
can occur.</p>
<h4>Declaration</h4><code class="language-swift">public subscript&lt;Index>(index: SIMD16&lt;Index>) where Index: FixedWidthInteger, Index: SIMDScalar, Self.Scalar: SIMDScalar -> SIMD16&lt;Self.Scalar></code></div></div><div id="subscript_index-293ad0a56dee4ecca71b95ccc73897e9" class="declaration"><a class="toggle-link" href="#comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9">subscript subscript(index:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9"><p>Extracts the scalars at specified indices to form a SIMD32.</p>
<p>The elements of the index vector are wrapped modulo the count of elements
in this vector. Because of this, the index is always in-range and no trap
can occur.</p>
<h4>Declaration</h4><code class="language-swift">public subscript&lt;Index>(index: SIMD32&lt;Index>) where Index: FixedWidthInteger, Index: SIMDScalar, Self.Scalar: SIMDScalar -> SIMD32&lt;Self.Scalar></code></div></div><div id="subscript_index-293ad0a56dee4ecca71b95ccc73897e9" class="declaration"><a class="toggle-link" href="#comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9">subscript subscript(index:)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-subscript_index-293ad0a56dee4ecca71b95ccc73897e9"><p>Extracts the scalars at specified indices to form a SIMD64.</p>
<p>The elements of the index vector are wrapped modulo the count of elements
in this vector. Because of this, the index is always in-range and no trap
can occur.</p>
<h4>Declaration</h4><code class="language-swift">public subscript&lt;Index>(index: SIMD64&lt;Index>) where Index: FixedWidthInteger, Index: SIMDScalar, Self.Scalar: SIMDScalar -> SIMD64&lt;Self.Scalar></code></div></div><h3>Instance Methods</h3><div id="encode_to-8c7f999a44e91e36e6d67e62075ffdbb" class="declaration"><a class="toggle-link" href="#comment-encode_to-8c7f999a44e91e36e6d67e62075ffdbb">func encode(to encoder: Encoder) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode_to-8c7f999a44e91e36e6d67e62075ffdbb"><p>Encodes the scalars of this vector into the given encoder in an unkeyed
container.</p>
<p>This function throws an error if any values are invalid for the given
encoder's format.</p>
<ul>
<li>Parameter encoder: The encoder to write data to.</li>
</ul>
<h4>Declaration</h4><code class="language-swift">public func encode(to encoder: Encoder) throws</code></div></div><div id="hash_into-6d50cb3daa41162a12fb4542a687b393" class="declaration"><a class="toggle-link" href="#comment-hash_into-6d50cb3daa41162a12fb4542a687b393">func hash(into hasher: inout Hasher)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-hash_into-6d50cb3daa41162a12fb4542a687b393"><p>Hashes the elements of the vector using the given hasher.</p>
<h4>Declaration</h4><code class="language-swift">@inlinable public func hash(into hasher: inout Hasher)</code></div></div><div id="replace_with_where-93841bb2bc72fd94768523031e4c6835" class="declaration"><a class="toggle-link" href="#comment-replace_with_where-93841bb2bc72fd94768523031e4c6835">func replace(with other: Self, where mask: SIMDMask&lt;Self.MaskStorage>)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-replace_with_where-93841bb2bc72fd94768523031e4c6835"><p>Replaces elements of this vector with elements of <code>other</code> in the lanes
where <code>mask</code> is <code>true</code>.</p>
<h4>Declaration</h4><code class="language-swift">public mutating func replace(with other: Self, where mask: SIMDMask&lt;Self.MaskStorage>)</code></div></div><div id="replace_with_where-93841bb2bc72fd94768523031e4c6835" class="declaration"><a class="toggle-link" href="#comment-replace_with_where-93841bb2bc72fd94768523031e4c6835">func replace(with other: Self.Scalar, where mask: SIMDMask&lt;Self.MaskStorage>)</a> <span class="required">Required</span><div class="comment collapse in" id="comment-replace_with_where-93841bb2bc72fd94768523031e4c6835"><p>Replaces elements of this vector with <code>other</code> in the lanes where <code>mask</code>
is <code>true</code>.</p>
<h4>Declaration</h4><code class="language-swift">public mutating func replace(with other: Self.Scalar, where mask: SIMDMask&lt;Self.MaskStorage>)</code></div></div><div id="replacing_with_where-dc4b2fcaa72a5e4572f0e8cd59238b6e" class="declaration"><a class="toggle-link" href="#comment-replacing_with_where-dc4b2fcaa72a5e4572f0e8cd59238b6e">func replacing(with other: Self, where mask: SIMDMask&lt;Self.MaskStorage>) -> Self</a> <span class="required">Required</span><div class="comment collapse in" id="comment-replacing_with_where-dc4b2fcaa72a5e4572f0e8cd59238b6e"><p>Returns a copy of this vector, with elements replaced by elements of
<code>other</code> in the lanes where <code>mask</code> is <code>true</code>.</p>
<h4>Declaration</h4><code class="language-swift">public func replacing(with other: Self, where mask: SIMDMask&lt;Self.MaskStorage>) -> Self</code></div></div><div id="replacing_with_where-dc4b2fcaa72a5e4572f0e8cd59238b6e" class="declaration"><a class="toggle-link" href="#comment-replacing_with_where-dc4b2fcaa72a5e4572f0e8cd59238b6e">func replacing(with other: Self.Scalar, where mask: SIMDMask&lt;Self.MaskStorage>) -> Self</a> <span class="required">Required</span><div class="comment collapse in" id="comment-replacing_with_where-dc4b2fcaa72a5e4572f0e8cd59238b6e"><p>Returns a copy of this vector, with elements <code>other</code> in the lanes where
<code>mask</code> is <code>true</code>.</p>
<h4>Declaration</h4><code class="language-swift">public func replacing(with other: Self.Scalar, where mask: SIMDMask&lt;Self.MaskStorage>) -> Self</code></div></div><h3>Type Methods</h3><div id="lhs_rhs-6b971e58c53aca8889c4170bed357094" class="declaration"><a class="toggle-link" href="#comment-lhs_rhs-6b971e58c53aca8889c4170bed357094">func .!=(lhs: Self, rhs: Self) -> SIMDMask&lt;Self.MaskStorage></a> <span class="required">Required</span><div class="comment collapse in" id="comment-lhs_rhs-6b971e58c53aca8889c4170bed357094"><p>Returns a vector mask with the result of a pointwise inequality
comparison.</p>
<h4>Declaration</h4><code class="language-swift">public static func .!=(lhs: Self, rhs: Self) -> SIMDMask&lt;Self.MaskStorage></code></div></div><div id="lhs_rhs-6b971e58c53aca8889c4170bed357094" class="declaration"><a class="toggle-link" href="#comment-lhs_rhs-6b971e58c53aca8889c4170bed357094">func .!=(lhs: Self.Scalar, rhs: Self) -> SIMDMask&lt;Self.MaskStorage></a> <span class="required">Required</span><div class="comment collapse in" id="comment-lhs_rhs-6b971e58c53aca8889c4170bed357094"><p>Returns a vector mask with the result of a pointwise inequality comparison.</p>
<h4>Declaration</h4><code class="language-swift">public static func .!=(lhs: Self.Scalar, rhs: Self) -> SIMDMask&lt;Self.MaskStorage></code></div></div><div id="lhs_rhs-6b971e58c53aca8889c4170bed357094" class="declaration"><a class="toggle-link" href="#comment-lhs_rhs-6b971e58c53aca8889c4170bed357094">func .!=(lhs: Self, rhs: Self.Scalar) -> SIMDMask&lt;Self.MaskStorage></a> <span class="required">Required</span><div class="comment collapse in" id="comment-lhs_rhs-6b971e58c53aca8889c4170bed357094"><p>Returns a vector mask with the result of a pointwise inequality comparison.</p>
<h4>Declaration</h4><code class="language-swift">public static func .!=(lhs: Self, rhs: Self.Scalar) -> SIMDMask&lt;Self.MaskStorage></code></div></div><div id="lhs_rhs-1074002e56e077c1d6f35c671c2db9c8" class="declaration"><a class="toggle-link" href="#comment-lhs_rhs-1074002e56e077c1d6f35c671c2db9c8">func .==(lhs: Self, rhs: Self) -> SIMDMask&lt;Self.MaskStorage></a> <span class="required">Required</span><div class="comment collapse in" id="comment-lhs_rhs-1074002e56e077c1d6f35c671c2db9c8"><p>Returns a vector mask with the result of a pointwise equality comparison.</p>
<h4>Declaration</h4><code class="language-swift">public static func .==(lhs: Self, rhs: Self) -> SIMDMask&lt;Self.MaskStorage></code></div></div><div id="lhs_rhs-1074002e56e077c1d6f35c671c2db9c8" class="declaration"><a class="toggle-link" href="#comment-lhs_rhs-1074002e56e077c1d6f35c671c2db9c8">func .==(lhs: Self.Scalar, rhs: Self) -> SIMDMask&lt;Self.MaskStorage></a> <span class="required">Required</span><div class="comment collapse in" id="comment-lhs_rhs-1074002e56e077c1d6f35c671c2db9c8"><p>Returns a vector mask with the result of a pointwise equality comparison.</p>
<h4>Declaration</h4><code class="language-swift">public static func .==(lhs: Self.Scalar, rhs: Self) -> SIMDMask&lt;Self.MaskStorage></code></div></div><div id="lhs_rhs-1074002e56e077c1d6f35c671c2db9c8" class="declaration"><a class="toggle-link" href="#comment-lhs_rhs-1074002e56e077c1d6f35c671c2db9c8">func .==(lhs: Self, rhs: Self.Scalar) -> SIMDMask&lt;Self.MaskStorage></a> <span class="required">Required</span><div class="comment collapse in" id="comment-lhs_rhs-1074002e56e077c1d6f35c671c2db9c8"><p>Returns a vector mask with the result of a pointwise equality comparison.</p>
<h4>Declaration</h4><code class="language-swift">public static func .==(lhs: Self, rhs: Self.Scalar) -> SIMDMask&lt;Self.MaskStorage></code></div></div><div id="lhs_rhs-28a45cba8101c0b1017a22535b8b2710" class="declaration"><a class="toggle-link" href="#comment-lhs_rhs-28a45cba8101c0b1017a22535b8b2710">func ==(lhs: Self, rhs: Self) -> Bool</a> <span class="required">Required</span><div class="comment collapse in" id="comment-lhs_rhs-28a45cba8101c0b1017a22535b8b2710"><p>Returns a Boolean value indicating whether two vectors are equal.</p>
<h4>Declaration</h4><code class="language-swift">public static func ==(lhs: Self, rhs: Self) -> Bool</code></div></div>